#include<iostream>
#include<vector>
#include<unistd.h>
#include<assert.h>
using namespace std;
const int gnum = 3;
class EndPoint
{
private:



public:
    pid_t _child_id;
    int _write_fd;

    EndPoint(int id, int fd) : _child_id(id), _write_fd(fd)
    {
        
    }

    
};

 void WaitConmmand()
 {

    while (true)
    {
        int command = 0;
        int n = read(0, &command, sizeof(int));
        if (n == sizeof(int))
        {
            //执行的任务
        }
        else if (n == 0)
        {
            std::cout << "父进程让我退出，我就退出了: " << getpid() << std::endl; 
            break;
        }
        else
        {
            break;
        }
    }

 }

void CreatProcesses(vector<EndPoint>* end_points)
{
    vector<int> fds;
    for(int i = 0;i < gnum; i++)
    {
        int pipefd[2] = {0};
        int n = pipe(pipefd);
        assert(n);
        (void)n;

        pid_t id = fork();
        assert(id!=-1);
        if(id == 0)
        {
            for(auto &fd:fds) close(fd);
            close(pipefd[1]);
            
            
            dup2(pipefd[0],0);
            WaitConmmand();
            close(pipefd[0]);
            exit(0);

        }

        close(pipefd[0]);
        end_points->push_back(EndPoint(id, pipefd[1]));
        fds.push_back(pipefd[1]);
    }
}

int main()
{
    vector<EndPoint>* end_points;

    CreatProcesses(end_points);
}